
/*
 * Hlpay-Plus aggregate payment system.
 * Copyright (c) 2024-2025 Hlpay Team Copyright has the right of final interpretation.
 */

package com.hlkj.pay.controller.openapi;

import java.util.Map;

import com.hlkj.framework.common.util.json.JsonUtils;
import com.hlkj.pay.util.SignUtils;
import com.hlkj.pay.vo.openapi.merchant.req.access.OpenApiMerchantAccessQueryReq;
import com.hlkj.pay.vo.order.req.OrderCommonParamReq;
import com.hlkj.pay.vo.order.req.PayOrderCommonParamReq;
import com.hlkj.pay.vo.order.req.PayOrderParamReq;

import cn.hutool.core.bean.BeanUtil;
import lombok.extern.slf4j.Slf4j;

/**
 * @author HlpayTeam
 * @data 2022/2/8 13:22
 */
@Slf4j
public class OpenApiParams {

    public static void main(String[] args) throws Exception {
        // testSubmitOrder();
        // online();
        testAccessDetail();
        String json="{\"mchOrderNo\":\"2024122715375719827\",\"notifyUrl\":\"https://www.mangay.cn/addons/ddrive/lfpaynotify/audit_notify\",\"providerCode\":\"S9033231002\",\"channelCode\":\"fuiou\",\"merchantAccessInfo\":{\"type\":1,\"merchantAccessLicense\":null,\"merchantAccessLegal\":{\"name\":\"哈哈哈\",\"phone\":\"17600125325\",\"address\":\"江西 九江\",\"certType\":\"1\",\"certNo\":\"142303199907801423\",\"certValidityType\":1,\"certBeginDate\":\"2024-12-31\",\"certEndDate\":\"2099-12-31\",\"certFrontUrl\":\"https://www.mangay.cn/public/assets/img/logo.png\",\"certBackUrl\":\"https://www.mangay.cn/public/assets/img/logo.png\",\"email\":\"17600125325@163.com\"},\"contactType\":1,\"merchantAccessContact\":null,\"controllerType\":1,\"merchantAccessController\":null,\"merchantAccessBenefitList\":null,\"merchantAccessShareholderList\":null},\"merchantAccessBusiness\":{\"shortName\":\"司机-哈哈哈\",\"mcc\":\"4121\",\"wechatMcc\":null,\"alipayMcc\":null,\"storeHeaderUrl\":\"https://www.mangay.cn/public/assets/img/logo.png\",\"storeIndoorUrl\":\"https://www.mangay.cn/public/assets/img/logo.png\",\"storeCashierDeskUrl\":\"https://www.mangay.cn/public/assets/img/logo.png\",\"servicePhone\":\"400-123456\",\"provinceCode\":\"010000\",\"cityCode\":\"010100\",\"areaCode\":\"010101\",\"address\":\"江西 九江\",\"officeSpace\":null,\"officeSpaceType\":null,\"businessDesc\":null,\"businessLicenses\":null,\"fileUrls\":null,\"merchantAccessSceneList\":null,\"sceneType\":null},\"merchantAccessCard\":{\"type\":1,\"name\":\"哈哈哈\",\"cardNo\":\"123456789123456789\",\"bankCode\":null,\"bankName\":null,\"branchCode\":null,\"officialName\":null,\"officialCardNo\":null,\"officialBankCode\":null,\"officialBankName\":null,\"officialBranchCode\":null,\"officialProvinceCode\":null,\"officialCityCode\":null,\"officialAreaCode\":null,\"certType\":null,\"certFrontUrl\":null,\"certBackUrl\":null,\"certNo\":null,\"certValidityType\":null,\"certBeginDate\":null,\"certEndDate\":null,\"provinceCode\":\"010000\",\"cityCode\":\"010100\",\"areaCode\":\"010101\",\"address\":null,\"cardPhone\":null,\"settleCardFrontUrl\":null,\"settleCertFrontUrl\":null,\"settleCertBackUrl\":null,\"licenseUrl\":null,\"licenseNo\":null,\"authUrl\":null,\"settleCycle\":4}}";
    }

    public static void onlineSubmitOrder() throws Exception {
        OrderCommonParamReq orderCommonParamReq = new OrderCommonParamReq();
        orderCommonParamReq.setAppId("APP_9569707003");
        orderCommonParamReq.setTimestamp(String.valueOf(System.currentTimeMillis() / 1000));
        orderCommonParamReq.setSignType("RSA2");
        orderCommonParamReq.setRequestId(System.currentTimeMillis() + "");

        PayOrderParamReq payOrderParamReq = new PayOrderParamReq();
        payOrderParamReq.setPayType("WECHAT");
        payOrderParamReq.setPaySubType("H5");
        payOrderParamReq.setSceneType(1);
        payOrderParamReq.setProviderCode("S9033231002");
        payOrderParamReq.setChannelCode("fuiou");
        // payOrderParamReq.setSubChannelCode("5");
        payOrderParamReq.setMchOrderNo("M" + System.currentTimeMillis());
        payOrderParamReq.setAmount("0.01");
        payOrderParamReq.setClientIp("219.140.119.128");
        payOrderParamReq.setSubject("测试商品");
        payOrderParamReq.setDescription("测试描述");
        // payOrderParamReq.setExtra("");
        payOrderParamReq.setNotifyUrl("");
        payOrderParamReq.setRedirectUrl("");
        payOrderParamReq.setExpiredTime(30 * 60);
        PayOrderCommonParamReq.Extra extra = new PayOrderCommonParamReq.Extra();
        extra.setAuthCode("132122627647230360");
        payOrderParamReq.setExtra(extra);
        // payOrderParamReq.setFundProcessType();
        // payOrderParamReq.setAcctInfos();
        // orderCommonParamReq.setBizContent(payOrderParamReq);
        Map<String, Object> stringObjectMap = BeanUtil.beanToMap(orderCommonParamReq);
        stringObjectMap.put("bizContent", JsonUtils.toJsonString(payOrderParamReq));
        log.info("bodyJson:{}", JsonUtils.toJsonString(stringObjectMap));
        String sign = SignUtils.signRsa(stringObjectMap, privateKey(), orderCommonParamReq.getSignType());
        stringObjectMap.put("sign", sign);
        // log.info("checkSignByPubKey:{}", SignUtils.verify(signParams, pubKey()));
        String bodyJson = JsonUtils.toJsonString(stringObjectMap);
        log.info("bodyJson:{}", bodyJson);
    }

    public static void testSubmitOrder() throws Exception {
        OrderCommonParamReq orderCommonParamReq = new OrderCommonParamReq();
        orderCommonParamReq.setAppId("APP_1961555003");
        orderCommonParamReq.setTimestamp(String.valueOf(System.currentTimeMillis() / 1000));
        orderCommonParamReq.setSignType("RSA2");
        orderCommonParamReq.setRequestId(System.currentTimeMillis() + "");

        PayOrderParamReq payOrderParamReq = new PayOrderParamReq();
        payOrderParamReq.setPayType("WECHAT");
        payOrderParamReq.setPaySubType("NATIVE");
        payOrderParamReq.setSceneType(1);
        payOrderParamReq.setProviderCode("S1524906003");
        payOrderParamReq.setChannelCode("lakala");
        // payOrderParamReq.setSubChannelCode("5");
        payOrderParamReq.setMchOrderNo("M" + System.currentTimeMillis());
        payOrderParamReq.setAmount("0.01");
        payOrderParamReq.setClientIp("219.140.119.128");
        payOrderParamReq.setSubject("测试商品");
        payOrderParamReq.setDescription("测试描述");
        // payOrderParamReq.setExtra("");
        payOrderParamReq.setNotifyUrl("");
        payOrderParamReq.setRedirectUrl("");
        payOrderParamReq.setExpiredTime(30 * 60);
        PayOrderCommonParamReq.Extra extra = new PayOrderCommonParamReq.Extra();
        extra.setAuthCode("132122627647230360");
        payOrderParamReq.setExtra(extra);
        // payOrderParamReq.setFundProcessType();
        // payOrderParamReq.setAcctInfos();
        // orderCommonParamReq.setBizContent(payOrderParamReq);
        Map<String, Object> stringObjectMap = BeanUtil.beanToMap(orderCommonParamReq);
        stringObjectMap.put("bizContent", JsonUtils.toJsonString(payOrderParamReq));
        log.info("bodyJson:{}", JsonUtils.toJsonString(stringObjectMap));
        String sign = SignUtils.signRsa(stringObjectMap, privateKey(), orderCommonParamReq.getSignType());
        stringObjectMap.put("sign", sign);
        // log.info("checkSignByPubKey:{}", SignUtils.verify(signParams, pubKey()));
        String bodyJson = JsonUtils.toJsonString(stringObjectMap);
        log.info("bodyJson:{}", bodyJson);
    }
    public static void testAccessDetail() throws Exception {
        OrderCommonParamReq orderCommonParamReq = new OrderCommonParamReq();
        orderCommonParamReq.setAppId("APP_1961555003");
        orderCommonParamReq.setTimestamp(String.valueOf(System.currentTimeMillis() / 1000));
        orderCommonParamReq.setSignType("RSA2");
        orderCommonParamReq.setRequestId(System.currentTimeMillis() + "");

        OpenApiMerchantAccessQueryReq payOrderParamReq = new OpenApiMerchantAccessQueryReq();
        payOrderParamReq.setRequestId("1869248008381292544");
        Map<String, Object> stringObjectMap = BeanUtil.beanToMap(orderCommonParamReq);
        stringObjectMap.put("bizContent", JsonUtils.toJsonString(payOrderParamReq));
        log.info("bodyJson:{}", JsonUtils.toJsonString(stringObjectMap));
        String sign = SignUtils.signRsa(stringObjectMap, privateKey(), orderCommonParamReq.getSignType());
        stringObjectMap.put("sign", sign);
        // log.info("checkSignByPubKey:{}", SignUtils.verify(signParams, pubKey()));
        String bodyJson = JsonUtils.toJsonString(stringObjectMap);
        log.info("bodyJson:{}", bodyJson);
    }

    public static String privateKey() {
        // return
        // "MIIEvQIBADAN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sFGgyeFz";
    }

    public static String pubKey() {
        return "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAkh05Zv9wEdktdn/WUq94S/nSIR7rqJLBXr+H0VP2LiFXdXWKuEkcTAjDCoWjKmq+CAXcNCZnAq8wdO0w74eAzOhdVuhnel1nw8uPIwNVNP5s2o8puecvb83miZDgwsFxe/wqVKHeRXEJacNRFpd2GN/+x6A+43GGmZyQT4P84KziWjJPDWz9Jwg9IiO3Fwf8bpry/7VUWPtLPgZLqqf2nh1RrAHmUKiw9KEQlsXV9/T+BXOcDqr5IHLQ5TVM1DkrDuizjpXkuOlecTFECayY+itG/KD+Nfkgomp0H8zRd0EqBYhqbaXMJwKDCV+p8cnmyMwzmZs+pLFsxy152ekNkQIDAQAB";
    }

}
